<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
     <!-- 1 准备容器 
        2.引包
        3.创建实例
        4.添加配置项，完成渲染 
    -->
    <div id="app">
        <!-- 页面 -->
       <h3>书架</h3>
       <ul>
        <li v-for="(item,index) in booksList" :key="item.id">
            <span>{{item.name}}</span>
            <span>{{item.author}}</span>
            <button @click="del(item.id)">删除</button>
        </li>
       </ul>
    </div>
    <!-- vue2 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.13/vue.js"></script>
    <!-- vue3
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> -->
    <script>
        const app = new Vue({
            //通过el 配置选择器，指定Vue 管理那个div
            el: "#app",
            data:{//通过Data 提供数据
              booksList:[
                {id:1,name:"《红楼梦》",author:"曹雪芹"},
                {id:2,name:"《西游记》",author:"吴承恩"},
                {id:3,name:"《水浒传》",author:"施耐庵"},
                {id:4,name:"《三国演义》",author:"罗贯中"}
              ]
            },
            methods:{
                del(id){
                   this.booksList =  this.booksList.filter(item=>item.id!==id)
                }
            }
        });
    </script>
</body>
</html>